package cheme.Interpreter.AST.Variable;

import cheme.Interpreter.AST.Interfaces.IAstExpression;
import cheme.Interpreter.AST.Interfaces.IAstIdentifier;
import cheme.Interpreter.AST.Interfaces.IAstVariable;
import cheme.Interpreter.AST.Interfaces.IAstVariableDeclaration;
import cheme.Interpreter.AST.SymbolTable.SymbolTable;

public class AstVariableDeclaration extends AstVariableReference implements IAstVariableDeclaration
{
	static int id = 0;
	int myId = id++;
	
	public AstVariableDeclaration(SymbolTable symbolTable,
			IAstIdentifier identifier, IAstExpression expression)
	{
		super(symbolTable, identifier.toString());

		/*
		 * The base class constructor assures that the varaible exists, though 
		 * it may be in an implicit declaration state. This class needs to 
		 * resolve and ensure that the variable is in an explicit state.
		 */
		
		if(null != expression)
		{
			getReferrent().setExpression(expression);
			getReferrent().setDeclarationState(IAstVariable.DeclarationState.ExplicitDeclaration);
			
			// need to decide if the var is still unkown... the expression needs to tell us this...
		}
	}

	@Override
	public String toString()
	{
		return super.toString() + " : " + getReferrent().toString();
	}
}
